package com.sg.file.receive.provider.util.filereceive;

import com.sg.file.receive.api.dto.ByteFileReceiveRequest;
import com.sg.file.receive.api.dto.FileCreateDTO;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 文件接收基类
 * Created by asus on 2018/7/5.
 */
public abstract class AbstractFileReceive {

    private final static String DEFAULT_PATH="default";

    /**
     * 接收文件
     * @param fileReceiveRequest 文件上传请求
     * @return
     */
    public FileCreateDTO receive(ByteFileReceiveRequest fileReceiveRequest){
        if(StringUtils.isEmpty(fileReceiveRequest.getProName())){
            //如果项目路径为空则使用默认路径
            fileReceiveRequest.setProName(DEFAULT_PATH);
        }
        FileCreateDTO fileCreateDTO = doReceiveFile(fileReceiveRequest);
        return fileCreateDTO;
    }

    /**
     * 文件接收
     * @param fileReceiveRequest
     * @return
     */
    protected abstract FileCreateDTO doReceiveFile(ByteFileReceiveRequest fileReceiveRequest);
}
